package com.youma.wt.mvpbaselib;


import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import java.io.Serializable;

import butterknife.ButterKnife;

/**
**  类名：BaseActivity   创建目的： ""
**  作者：wangtong
**  时间:"2018/4/10 0010 17:30"
 * @object V  Interface for activity
 * @object T  Presenter for activity
*/
public  abstract class BaseActivity<V extends BaseViewInterface,T extends BasePrsenter> extends FragmentActivity{

    protected T mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = initPresenter();
        mPresenter.attchActivity((V) this);
        setContentView(getLayoutResId());
        ButterKnife.bind(this);
        initView();
    }

    protected abstract int getLayoutResId();

    protected abstract void initView();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.dettchActivity();
    }

    public abstract  T  initPresenter();



    public void transfer(Class<?> clazz) {
        try {
            Intent intent = new Intent(this, clazz);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    /**
     * 跳转界面
     *
     * @param clazz       要跳转的activity
     * @param requestCode 请求码
     */
    public void transfer(Class<?> clazz, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    /**
     * 跳转界面
     *
     * @param clazz  要跳转的activity
     * @param params intent中填入的参数名
     * @param obj    序列化的对象
     */
    public void transfer(Class<?> clazz, Serializable obj, String params) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    /**
     * 跳转界面
     *
     * @param clazz       要跳转的activity
     * @param params      intent中填入的参数名
     * @param obj         序列化的对象
     * @param requestCode 请求码
     */
    public void transfer(Class<?> clazz, Serializable obj, String params, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    /**
     * 跳转界面
     *
     * @param clazz       要跳转的activity
     * @param params      intent中填入的参数名
     * @param obj         序列化的对象
     * @param requestCode 请求码
     */
    public void transfer(Class<?> clazz, int obj, String params, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    /**
     * 跳转界面
     *
     * @param clazz       要跳转的activity
     * @param params2     传入的参数1
     * @param obj2        传入的int类型的值1
     * @param params      intent中填入的参数名2
     * @param obj         序列化的对象2
     * @param requestCode 请求码
     */
    public void transfer(Class<?> clazz, int obj2, String params2, Serializable obj, String params, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, int obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Boolean obj, String params, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, int obj, String params, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, boolean obj, String params) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, int obj, String params) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, Serializable obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, Serializable obj2, String params2, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, int obj2, String params2, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, boolean obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, boolean obj2, String params2, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, String obj2, String params2, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, String obj2, String params2, String obj3, String params3, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            intent.putExtra(params3, obj3);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, String obj1, String params1) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params1, obj1);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String obj, String params, String obj1, String params1, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params1, obj1);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, String obj1, String params1, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params1, obj1);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }
    public void transfer(Class<?> clazz, int obj, String params, String obj1, String params1, String obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params1, obj1);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, Serializable obj, String params, String obj1, String params1, String obj2, String params2, String obj3, String params3) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params1, obj1);
            intent.putExtra(params2, obj2);
            intent.putExtra(params3, obj3);
            startActivityForResult(intent, 0);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, String str, String params, int requestCode) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, str);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }


    public void transfer(Class<?> clazz, int requestCode, Serializable obj, String params) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }

    public void transfer(Class<?> clazz, int requestCode, Serializable obj, String params, Serializable obj2, String params2) {
        try {
            Intent intent = new Intent(this, clazz);
            intent.putExtra(params, obj);
            intent.putExtra(params2, obj2);
            startActivityForResult(intent, requestCode);
        } catch (Exception e) {
            doToast("该功能尚未开发,敬请期待");
        }
    }


    /**
     * @param id 图片的资源id
     * @return 返回当前项目下的图片drawable
     */
    public Drawable getBaseDrawable(int id) {

        Drawable drawable = ContextCompat.getDrawable(this, id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        return drawable;
    }

    /**
     * @param id 颜色的资源id
     * @return 返回当前项目下的具体色值
     */
    public int getBaseColor(int id) {
        return ContextCompat.getColor(this, id);
    }

    /**
     * activity静态toast
     */
    Toast toast;

    /**
     * 弹出一个吐司
     *
     * @param string 吐司内容
     */

    public void doToast(String string) {
        if (toast == null) {
            toast = Toast.makeText(this, string, Toast.LENGTH_SHORT);
        }
        toast.setText(string);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.show();
    }


}
